package com.swz.dcrm.ui.monthly;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyco.tablayout.SlidingTabLayout;
import com.swz.dcrm.adpter.FragmentViewPagerAdapter;
import com.swz.dcrm.adpter.GlobalAdapter;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.navigation.fragment.NavHostFragment;
import androidx.viewpager.widget.ViewPager;

import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;

import com.swz.dcrm.R;
import com.swz.dcrm.ui.daily.DailyComeShopFragment;
import com.swz.dcrm.ui.daily.DailyItemFragment;
import com.swz.dcrm.ui.daily.DailyTargetFragment;
import com.swz.dcrm.ui.daily.DailyTaskFragment;
import com.swz.dcrm.ui.daily.DaliyCustomerFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MonthlyFragment extends BaseFragment {

    @BindView(R.id.toolbar_title)
    TextView title;
    @BindView(R.id.tab)
    SlidingTabLayout slidingTabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;

    private List<String> titles;
    private List<Fragment> fragments;

    public static MonthlyFragment newInstance() {

        return new MonthlyFragment();
        // Required empty public constructor
    }

    @Override
    public void onLoadRetry() {
        if (!isNetworkConnected(getContext())){
            mHolder.showLoadingStatus(GlobalAdapter.NET_ERROR);
            return;
        }

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        onLoadRetry();
    }

    @Override
    public int layoutId() {
        return R.layout.fragment_monthly;
    }

    @Override
    public boolean initView() {
        getDigger().inject(this);
        title.setText(getString(R.string.monthly_title));

        titles= Arrays.asList(getResources().getStringArray(R.array.monthly_tab));
        fragments=new ArrayList<>();
        fragments.add(MonthlyGoalFragment.newInstance());
        fragments.add(MonthlyTargetFragment.newInstance());
        fragments.add(MonthlyStructureFragment.newInstance());
        fragments.add(MonthlyGraphFragment.newInstance());
        viewPager.setAdapter(new FragmentViewPagerAdapter(getChildFragmentManager(),fragments, titles));
        slidingTabLayout.setViewPager(viewPager);

        return true;
    }


    @OnClick(R.id.iv_back)
    public void backClick() {
        NavHostFragment.findNavController(this).navigateUp();
    }
}
